home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / portage / bin / regenworld < prev    next >
Encoding:
Text File  |  2006-06-30  |  2.9 KB  |  92 lines

  1. #!/usr/bin/python
  2. # Copyright 1999-2006 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. # $Id: /var/cvsroot/gentoo-src/portage/bin/regenworld,v 1.10.2.1 2005/01/11 03:40:57 carpaski Exp $
  5.  
  6. import sys
  7. sys.path.insert(0, "/usr/lib/portage/pym")
  8. import os
  9. import portage, string, re
  10.  
  11. __candidatematcher__ = re.compile("^[0-9]+: \\*\\*\\* emerge ")
  12. __noncandidatematcher__ = re.compile(" sync( |$)| clean( |$)| search( |$)|--oneshot| unmerge( |$)")
  13.  
  14. def issyspkg(pkgline):
  15.     return (pkgline[0] == "*")
  16.  
  17. def iscandidate(logline):
  18.     return (__candidatematcher__.match(logline) \
  19.                 and not __noncandidatematcher__.search(logline))
  20.  
  21. def getpkginfo(logline):
  22.     logline = re.sub("^[0-9]+: \\*\\*\\* emerge ", "", logline)
  23.     logline = logline.strip()
  24.     logline = re.sub("(\\S+\\.(ebuild|tbz2))|(--\\S+)|inject ", "", logline)
  25.     return logline.strip()
  26.  
  27. __uniqlist__ = []
  28. def isunwanted(pkgline):
  29.     if pkgline in ["world", "system", "depclean", "info", "regen", ""]:
  30.         return False
  31.     elif pkgline in __uniqlist__:
  32.         return False
  33.     elif not re.search("^[a-zA-Z<>=~]", pkgline):
  34.         return False
  35.     else:
  36.         __uniqlist__.append(pkgline)
  37.         return True
  38.  
  39. # show a little description if we have arguments
  40. if len(sys.argv) >= 2 and sys.argv[1] in ["-h", "--help"]:
  41.     print "This script regenerates the portage world file by checking the portage"
  42.     print "logfile for all actions that you've done in the past. It ignores any"
  43.     print "arguments except --help. It is recommended that you make a backup of"
  44.     print "your existing world file (%s) before using this tool." % portage.WORLD_FILE
  45.     sys.exit(0)
  46.  
  47. worldlist = portage.grabfile(os.path.join("/", portage.WORLD_FILE))
  48. syslist = portage.settings.packages
  49. syslist = filter(issyspkg, syslist)
  50.  
  51. logfile = portage.grabfile("/var/log/emerge.log")
  52. biglist = filter(iscandidate, logfile)
  53. biglist = map(getpkginfo, biglist)
  54. tmplist = []
  55. for l in biglist:
  56.     tmplist += l.split()
  57. biglist = filter(isunwanted, tmplist)
  58. #for p in biglist:
  59. #    print p
  60. #sys.exit(0)
  61.  
  62. # resolving virtuals
  63. realsyslist = []
  64. for mykey in syslist:
  65.     # drop the asterix
  66.     mykey = mykey[1:]
  67.     #print "candidate:",mykey
  68.     mylist=portage.db["/"]["vartree"].dbapi.match(mykey)
  69.     if mylist:
  70.         mykey=portage.cpv_getkey(mylist[0])
  71.         if mykey not in realsyslist:
  72.             realsyslist.append(mykey)
  73.  
  74. for mykey in biglist:
  75.     #print "checking:",mykey
  76.     try:
  77.         mylist=portage.db["/"]["vartree"].dbapi.match(mykey)
  78.     except KeyError:
  79.         if "--debug" in sys.argv:
  80.             print "* ignoring broken log entry for %s (likely injected)" % mykey
  81.     except ValueError, e:
  82.         print "* %s is an ambigous package name, candidates are:\n%s" % (mykey, e)
  83.         continue
  84.     if mylist:
  85.         #print "mylist:",mylist
  86.         myfavkey=portage.cpv_getkey(mylist[0])
  87.         if (myfavkey not in realsyslist) and (myfavkey not in worldlist):
  88.             print "add to world:",myfavkey
  89.             worldlist.append(myfavkey)
  90.  
  91. portage.write_atomic(os.path.join("/", portage.WORLD_FILE), "\n".join(worldlist))
  92.